import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)
// import register from "../pages/register/register.vue"
const register=()=>{
  console.log("register");
  return import("../pages/register/register.vue")
}
import login from "../pages/login/login.vue"
import index from "../pages/index/index.vue"
import list from "../pages/list/list.vue"
import detail from "../pages/detail/detail.vue"
import search from "../pages/search/search.vue"


import home from "../pages/home/home.vue"
import cate from "../pages/cate/cate.vue"
import shop from "../pages/shop/shop.vue"
import mine from "../pages/mine/mine.vue"

const routes = [
 {
   path:"/register",
   component:register,
   meta:{
     title:"注册"
   }
 },
 {
  path:"/login",
  component:login,
  meta:{
    title:"登陆"
  }
},
{
  path:"/index",
  component:index,
  children:[
    {path:"home",component:home,meta:{title:"首页"}},
    {path:"cate",component:cate,meta:{title:"分类"}},
    {path:"shop",component:shop,meta:{title:"购物车"}},
    {path:"mine",component:mine,meta:{title:"个人中心"}},

  ]
},
{
  path:"/list",
  component:list,
  meta:{
    title:"商品列表",
    back:true
  }
},
{
  path:"/detail/:id",
  component:detail,
  name:"详情",
  meta:{
    title:"商品详情页"
    
  }
},
{
  path:"/search",
  alias:"/s",
  name:"搜索",//命名路由
  component:search,
  meta:{
    title:"搜索",
    back:true
  }
},
{
  path:"*",
  component:index
}
]

const router = new VueRouter({
  //路由规则
  routes,
    //希望每进入一个新的路由，都从（0，0）开始
    scrollBehavior(to,from,savePosition){
      return savePosition?savePosition:{x : 0,y : 0}
    }
})

export default router
